package jp.tkym.labs.client.geom;

public class Matrix3f {
	float r00, r01, r02;
	float r10, r11, r12;
	float r20, r21, r22;
	
	Matrix3f(){
		r00 = 1.0f;
		r11 = 1.0f;
		r22 = 1.0f;
	}
	
	Vector3f getRow(int i){
		if(i==0) return new Vector3f(r00, r01, r02);
		if(i==1) return new Vector3f(r10, r11, r12);
		if(i==2) return new Vector3f(r20, r21, r22);
		throw new IllegalArgumentException("i is " + i);
	}
	
	Vector3f getCol(int i){
		if(i==0) return new Vector3f(r00, r10, r20);
		if(i==1) return new Vector3f(r01, r11, r21);
		if(i==2) return new Vector3f(r02, r12, r22);
		throw new IllegalArgumentException("i is " + i);
	}
	
	Matrix3f add(Matrix3f a){
		this.r00 += a.r00;
		this.r01 += a.r01;
		this.r02 += a.r02;
		this.r10 += a.r10;
		this.r11 += a.r11;
		this.r12 += a.r12;
		this.r20 += a.r20;
		this.r21 += a.r21;
		this.r22 += a.r22;
		return this;
	}
	
	protected Matrix3f clone(){
		Matrix3f clone = new Matrix3f();
		clone.r00 = this.r00;
		clone.r01 = this.r01;
		clone.r02 = this.r02;
		clone.r10 = this.r10;
		clone.r11 = this.r11;
		clone.r12 = this.r12;
		clone.r20 = this.r20;
		clone.r21 = this.r21;
		clone.r22 = this.r22;
		return clone;
	}
	
	Matrix3f multiply(Matrix3f left){
		Matrix3f clon = this.clone();
		this.r00 = clon.r00*left.r00 + clon.r01*left.r10 + clon.r02*left.r20;
		this.r01 = clon.r00*left.r01 + clon.r01*left.r11 + clon.r02*left.r21;
		this.r02 = clon.r00*left.r02 + clon.r01*left.r12 + clon.r02*left.r22;
		this.r10 = clon.r10*left.r00 + clon.r11*left.r10 + clon.r12*left.r20;
		this.r11 = clon.r10*left.r01 + clon.r11*left.r11 + clon.r12*left.r21;
		this.r12 = clon.r10*left.r02 + clon.r11*left.r12 + clon.r12*left.r22;
		this.r20 = clon.r20*left.r00 + clon.r21*left.r10 + clon.r22*left.r20;
		this.r21 = clon.r20*left.r01 + clon.r21*left.r11 + clon.r22*left.r21;
		this.r22 = clon.r20*left.r02 + clon.r21*left.r12 + clon.r22*left.r22;
		return this;
//		Vector3d r0 = this.getRow(0);
//		Vector3d r1 = this.getRow(1);
//		Vector3d r2 = this.getRow(2);
//		Vector3d l0 = left.getCol(0);
//		Vector3d l1 = left.getCol(1);
//		Vector3d l2 = left.getCol(2);
//		this.r00 = r0.inner(l0);
//		this.r01 = r0.inner(l1);
//		this.r02 = r0.inner(l2);
//		this.r10 = r1.inner(l0);
//		this.r11 = r1.inner(l1);
//		this.r12 = r1.inner(l2);
//		this.r20 = r2.inner(l0);
//		this.r21 = r2.inner(l1);
//		this.r22 = r2.inner(l2);
//		return this;
	}
}